import storage from '@/storage'
import keys from '@/storage/keys'

export default {
  state: {
    isLogin:false, // 是否登录
    userInfo:{}, // 个人信息
  },
  getters: {
    userInfo: state => {
      let loadFromStorage = async () => {
        storage.getItem(keys.userInfo).then(data => {
          data && (state.userInfo = data)
        })
      }
      if (Object.keys(state.userInfo).length === 0) {
        loadFromStorage()
      }
      console.log("333333333")
      return state.userInfo
    }
  },
  mutations: {
    // 更新 banner图片
    async updateUserInfoData(state, data) {
      storage.setItem(keys.userInfo, data)
    },
    // 更新 banner图片
    async updateIsLoginData(state, data) {
      storage.setItem(keys.isLogin, data)
    },
  }
}